package cn.echo.consul.manager.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.regex.Pattern.compile;

/**
 * 字符串处理
 * @author lonyee
 */
public class StringUtil {

    /**
     * 正则匹配编号格式
     *
     * @param code
     * @return
     */
    public static boolean isCode(String code) {
        Pattern pattern = compile("^[A-Za-z0-9_-]{4,30}$");
        Matcher m = pattern.matcher(code);
        return code != null && m.find();
    }

    /**
     * 正则匹配密码格式
     *
     * @param secret
     * @return
     */
    public static boolean isSecret(String secret) {
        Pattern pattern = compile("^(?=.*\\d)(?=.*[a-zA-Z]).{8,20}$");
        Matcher m = pattern.matcher(secret);
        return secret != null && m.find();
    }
}
